
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>添加小区</title>
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/admin.css"/>
    <style>
        .layui-form{
            /*  width: 350px; */
            height:280px;
            margin:0 auto;
        }
        #btn-c,#btn-s{
            margin-top:20px;
            border:0;
            width: 80px;
            height: 28px;
            border-radius:5px;
            background-color: #D8D8D8;
        }
        #btn-c{
            margin-left:54px;
        }
        #btn-s:hover,#btn-c:hover{
            color:#fff;
            background-color:#EF7632;
        }
        #btn-s{
            margin-left:3px;
        }
        .layui-form select{
            margin-top:20px;
        }
        .layui-btn, .layui-tree li i, .layui-unselect{
            width:fit-content;
        }
        .layui-input{
            border:1px solid #E5BA70;
            margin-top:10px;
            border-radius:5px;
            margin-left:64px;
            width:145px;
        }
        .layui-form-select .layui-input{
            padding-right:2px;
        }
        .layui-form-select dl{
            min-width:68%;
            margin-left:72px;
        }
        .layui-input, .layui-textarea{
            padding-left:10px;
        }
        .layui-form-select dl dd.layui-this{
            color:#2C273D;
            background-color:#fff;
        }
        .add-d{
            width:140px;
            height:34px;
            margin-top:10px;
            margin-left:65px;
            border-radius:5px;
            border:1px solid #E5BA70;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <!-- 省市选择模块 -->
    <select  id="province" name="province" lay-verify="required"  lay-filter="test">
        <option value="">请选择省份</option>
    </select>
    <select id="city" name="city" lay-verify="required" lay-filter="test1">
        <option value="">请选择城市</option>
    </select>
    <select id="district" name="district"  lay-verify="required" lay-filter="test2">
        <option value="">请选择区/县</option>
    </select>

    <input class="add-d" id="buli_name" type="text" placeholder="请输入小区..." onfocus="this.style.color='#2C273D';
    this.value='';"  onblur="this.style.color='#2C273D';" > <br/>

    <input class="add-d" id="zhuang_num" type="text" placeholder="请输入小区幢数..." onfocus="this.style.color='#2C273D';
    this.value='';"  onblur="this.style.color='#2C273D';" >
    <select id="tax_MS" name="district"  lay-verify="required" lay-filter="test3">
        <option value="" name="">选择小区类型</option>
        <option value="0" name="busy" selected="">商务楼</option>
        <option value="1" name="live" selected="">住宅楼</option>
    </select>
    <select id="tax_S" name="district"  lay-verify="required" lay-filter="test7">
        <option value="">乘坐类型</option>
        <option value="0" selected="">开放指定楼层</option>
        <option value="1" selected="">全开放</option>
    </select>
    <select id="tax_M" name="district"  lay-verify="required" lay-filter="test4">
        <option value="">乘坐是否收费</option>
        <option value="0" selected="">免费乘坐</option>
        <option value="1" selected="">收费乘坐</option>
    </select>
    <input class="add-d" id="tax_MY" type="text" placeholder="单次乘坐额度" onfocus="this.style.color='#2C273D';
    this.value='';"  onblur="this.style.color='#2C273D';" >

    <select id="name_M" name="district"  lay-verify="required" lay-filter="test5">
        <option value="">注册是否收费</option>
        <option value="0" selected="">免费注册</option>
        <option value="1" selected="">收费注册</option>
    </select>
    <input class="add-d" id="name_MM" type="text" placeholder="注册收费标注" onfocus="this.style.color='#2C273D';
    this.value='';"  onblur="this.style.color='#2C273D';" > <br/>
    <select id="name_ck" name="district"  lay-verify="required" lay-filter="test6">
        <option value="">注册是否审核</option>
        <option value="0" selected="">无需审核</option>
        <option value="1" selected="">需要审核</option>
    </select>
    <input class="add-d" id="tax_free" type="text" placeholder="免费乘坐次数" onfocus="this.style.color='#2C273D';
    this.value='';"  onblur="this.style.color='#2C273D';" >

    <input type="button" id="btn-c" value="取消">
    <input type="button" id="btn-s" value="保存">
</form>
<script type="text/javascript" src="../layui/layui.js"></script>
<script>

    layui.use(['jquery','form','upload','layer'],function(){

        var layer = layui.layer;
        var $ = layui.jquery;
        var form = layui.form();

        var user_id = window.localStorage.getItem("user_id");
        console.log(user_id );

        var wuyeId = user_id;
        console.log(wuyeId);

        var params = {};

        $.ajax({
            url: '../../organization_manage/getProvinces',
            type: "GET",
            data: {
                wuye_id: wuyeId
            },
            success: function(response){
                var response = JSON.parse(response);
                console.log(response);

                if(response.resultCode == 200){
                    var str='';
                    for(var i=0;i<response.provinces.length;i++){
                        str+='<option value="' + response.provinces[i].province_id +'">'+ response.provinces[i].province_name +'</option>';
                    }//for
                    console.log(str);
                    $("#province").append(str);
                    layui.use(['jquery','form','layer'],function(){
                        var layer = layui.layer;
                        var $ = layui.jquery;
                        var form = layui.form();
                        form.render();

                        form.on('select(test)', function(data){
                            var provinceId = data.value;
                            console.log(provinceId );

                            var provinceName = data.elem[data.elem.selectedIndex].text;
                            params.province_id = provinceId;
                            params.province_name = provinceName;

                            console.log('params.province_id',params.province_id);
                            console.log('params.province_name',params.province_name);
                            if(provinceId){
                                $("#city").attr("disabled", false);
                                $("#district").attr("disabled", true);
                                $.ajax({
                                    url: '../../organization_manage/getCitys',
                                    type: "GET",
                                    data: {
                                        wuye_id:wuyeId,
                                        province_id: provinceId
                                    },
                                    success: function(response){
                                        var response = JSON.parse(response);
                                        console.log(response);
                                        if(response.resultCode == 200){
                                            var str='';
                                            for(var i=0;i<response.citys.length;i++){
                                                str += '<option value="' + response.citys[i].city_id +'">'+ response.citys[i].city_name +'</option>';
                                            }
                                            $("#city").append(str);

                                            layui.use(['jquery','form','layer'],function(){
                                                var layer = layui.layer;
                                                var $ = layui.jquery;
                                                var form = layui.form();
                                                form.render();
                                                form.on('select(test1)',function(data){

                                                    var cityId = data.value;
                                                    var cityName = data.elem[data.elem.selectedIndex].text;
                                                    params.city_id = cityId;
                                                    params.city_name = cityName;

                                                    console.log('params.city_id',params.city_id);
                                                    console.log('params.city_name',params.city_name);
                                                    console.log(cityId);
                                                    if(cityId){
                                                        $("#district").attr("disabled", false);
                                                        $.ajax({
                                                            url: '../../organization_manage/getDistricts',
                                                            type: "GET",
                                                            data: {
                                                                wuye_id: wuyeId,
                                                                city_id: cityId
                                                            },
                                                            success: function(response){
                                                                var response = JSON.parse(response);
                                                                console.log(response);
                                                                if(response.resultCode == 200){
                                                                    var str='';
                                                                    for(var i=0;i<response.districts.length;i++){
                                                                        str+='<option value="' + response.districts[i].district_id +'">'+ response.districts[i].district_name +'</option>';
                                                                    }

                                                                    var districts   = response.districts;
                                                                    console.log(districts );

                                                                    $("#district").append(str);
                                                                    layui.use(['jquery','form','layer'],function(){
                                                                        var layer = layui.layer;
                                                                        var $ = layui.jquery;
                                                                        var form = layui.form();
                                                                        form.render();
                                                                        form.on('select(test2)',function(data){
                                                                            var districtId = data.value;
                                                                            var districtName = data.elem[data.elem.selectedIndex].text;
                                                                            params.district_id = districtId;
                                                                            params.district_name = districtName;
                                                                            console.log('params.district_id',params.district_id);
                                                                            console.log('params.district_name',params.district_name);
                                                                            console.log(districtId);
                                                                        })
                                                                    })//区模块加载
                                                                }//200
                                                            }//success
                                                        })//ajax
                                                    }else{
                                                        $("#district").attr("disabled", true);
                                                    }
                                                })//市加载县
                                            })//市模块加载
                                        } //200
                                    }  //success
                                })//市ajax
                            }else{
                                $("#city").attr("disabled", true);
                                $("#district").attr("disabled", true);
                            }
                        })//省级加载市级 for
                        //新增 下拉获取值
                        form.on('select(test3)',function(data){
                            var styleValue = data.value;
                            var styleName = data.elem[data.elem.selectedIndex].text;
                            params.styleValue = styleValue;
                            params.styleName = styleName;
                            console.log('params.styleValue',params.styleValue);
                            console.log('params.styleName',params.styleName);
                        })
                        form.on('select(test4)',function(data){
                            var chengValue = data.value;
                            var chengName = data.elem[data.elem.selectedIndex].text;
                            params.chengValue = chengValue;
                            params.chengName = chengName;
                            console.log('params.chengValue',params.chengValue);
                            console.log('params.Name',params.chengName);
                        });

                        form.on('select(test5)',function(data){
                            var shouValue = data.value;
                            var shouName = data.elem[data.elem.selectedIndex].text;
                            params.shouValue = shouValue;
                            params.shouName = shouName;
                            console.log('params.shouValue',params.shouValue);
                            console.log('params.shouName',params.shouName);
                        })
                        form.on('select(test6)',function(data){
                            var shenValue = data.value;
                            var shenName = data.elem[data.elem.selectedIndex].text;
                            params.is_check = shenValue;
                            params.shenName = shenName;
                            console.log('params.is_check',params.is_check);
                            console.log('params.shenName',params.shenName);
                        })
                        form.on('select(test7)',function(data){
                            var styleValue = data.value;
                            var styleName = data.elem[data.elem.selectedIndex].text;
                            params.chengti_type = styleValue;
                            params.styleName = styleName;
                            console.log('params.chengti_type',params.chengti_type);
                            console.log('params.styleName',params.styleName);
                        })
                    })  //模块加载
                }//200
            }//success
        }) //ajax
        $("#btn-s").click(function(){

            var Building_name = $("#buli_name").val();
            params.building_name = Building_name;
            console.log('params.building_name',params.building_name);
            console.log(params);

            var zhuang_name = $("#zhuang_num").val();
            params.zhuang_name = zhuang_name;
            console.log('params.zhuang_name',params.zhuang_name);

            var price = $("#tax_MY").val();
            console.log(price);

            if(params.chengValue == 1){
                params.price = price;
                console.log('params.price',params.price);
            }else if(params.chengValue == 0){
                params.price = 0;
            }else{
                alert("请选择乘坐类型")
            };

            var reg_charge = $("#name_MM").val();
            console.log(reg_charge);

            var Free_time = $("#tax_free").val();
            params.Free_time = Free_time;
            console.log('params.Free_time',params.Free_time);

            if(params.shouValue == 1){
                params.reg_charge = reg_charge;
                console.log('params.reg_charge',params.reg_charge);
            }else if(params.shouValue == 0){
                params.reg_charge = 0;
            }else{
                alert("请先选择是否收费")
            };

            if(!params.province_id){
                alert("请先选择一个省！")
                return;
            }else if(!params.city_id){
                alert("请先选择一个市！");
                return;
            }else if(!params.district_id){
                alert("请先选择一个县！");
                return;
            }else if(!params.building_name){
                alert("请输入小区名字");
                return;
            }
            $.ajax({
                url: "../../organization_manage/addBuilding",
                type: "post",
                data: {
                    province_id:params.province_id,
                    province_name:params.province_name,
                    city_id:params.city_id,
                    city_name:params.city_name,
                    district_id:params.district_id,
                    district_name:params.district_name,
                    building_name:params.building_name,
                    price:params.price,
                    reg_charge:params.reg_charge,
                    is_check:params.is_check,
                    building_type:params.styleValue,
                    chengti_type:params.chengti_type,
                    reg_gift:params.Free_time
                },
                success: function(response){
                    var response = JSON.parse(response);
                    console.log(response);
                    alert("添加成功");
                    window.parent.location.reload();
                    var index=parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    if(response.resultCode == '200'){
                    }
                },
                error:function(response){
                    console.log(response);
                    alert("添加失败");
                    window.parent.location.reload();
                    var index=parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                    if(response.resultCode=='001'){
                        console.log("param is not found")
                    }
                }
            })
        })//保存
        $("#btn-c").click(function(){
            window.parent.location.reload();
            var index=parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
        })
    });//模块加载
</script>
</body>
</html>
